<?

/**
* local collection functions of tocmenu_13
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
   * list of data detail
   *
   * @param object  $Db
   * @param string  $jobId
   * @param string  $srcDb
   * @param integer $nDetail
   * @param array   $lstDetail
   */
  function fetchLstDataDetail(&$Db,
                              &$jobId,
                               $srcDb,
                              &$nDetail,
                              &$lstDetail){

    $query	= "SELECT UNIT_NAME,
                      UNIT_TO,
                      QTY
               FROM ".$srcDb."
               WHERE	JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nDetail,
                        $lstDetail);
  }

  /**
   * list of data header
   *
   * @param object   $Db
   * @param string   $jobId
   * @param Composer $SourceDb
   * @param integer  $nHeader
   * @param array    $lstHeader
   */
  function fetchLstDataHeader(&$Db,
                              &$jobId,
                              &$SourceDb,
                              &$nHeader,
                              &$lstHeader){

    $query	= "SELECT DISTINCT
                      M.MODEL
               FROM ".$SourceDb->fetchValue("srcDbHdr")." M,
                    ".$SourceDb->fetchValue("srcDbDtl")." C
               WHERE	C.JOB_ID='".$jobId."'
                      AND M.MODEL_ID=C.MODEL_ID ";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $lstHeader);
  }

  /**
   * model Id
   *
   * @param Database $Db
   * @param string   $modelName
   * @param string   $srcDb
   * @param integer  $modelId
   */
  function fetchModelId(&$Db,
                        &$modelName,
                         $srcDb,
                        &$modelId){

    $query	= "SELECT MODEL_ID
               FROM ".$srcDb."
               WHERE	MODEL='".$modelName."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $modelId = $result["MODEL_ID"][0];
  }

  /**
   * original model' unit
   *
   * @param Database  $Db
   * @param string    $model
   * @param Composer  $SourceDb
   * @param string    $unitFrom
   */
  function fetchUnitFrom(&$Db,
                         &$model,
                         &$SourceDb,
                         &$unitFrom){

    $query	= "SELECT M.UNIT
               FROM ".$SourceDb->fetchValue("srcDbMstModel")." M
               WHERE	M.MODEL='".$model."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $unitFrom = $result["UNIT"][0];
  }

  /**
   * list of transaction
   *
   * @param Database $Db
   * @param string   $condt
   * @param Composer $SourceDb
   * @param integer  $nrows
   * @param array    $res
   */
  function fetchLstTransaction(&$Db,
                                $condt,
                               &$SourceDb,
                               &$nrows,
                               &$res){

    $query	= "SELECT DISTINCT
                      C.JOB_ID,
                      C.MODEL_ID,
                      M.MODEL
               FROM ".$SourceDb->fetchValue("srcDbDtl")." C,
                    ".$SourceDb->fetchValue("srcDbHdr")." M
               WHERE C.MODEL_ID=M.MODEL_ID
               ORDER BY M.MODEL ASC ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $res);
  }
}

?>